package edu.sysu.demo.petstore.dog.web.rest;

import edu.sysu.demo.petstore.dog.data.entity.User;
import edu.sysu.demo.petstore.dog.user.RegisterService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/account/register")
public class RegisterController {

  private final RegisterService registerService;

  public RegisterController(RegisterService registerService) {
    this.registerService = registerService;
  }

  @PostMapping
  public RegisterResult register(@RequestBody RegisterForm form) {
    User user = registerService.register(form.getUsername(), form.getPassword());
    return new RegisterResult(user.getId(), user.getUsername());
  }
}

